package jmvm.main;



import java.awt.*;
import java.awt.event.*;

import java.io.*;





import javax.swing.*;

import jmvm.assembler.Assembler;
import jmvm.components.*;
import jmvm.gui.GuiScheme;
import jmvm.schemes.*;



@SuppressWarnings("serial")
public class Main extends JFrame {
	
	//
	//
	// GRAFIKA
	//
	//
	JPanel east = new JPanel();
	JPanel northeast = new JPanel();
	JPanel southeast = new JPanel();
	JPanel west = new JPanel();

	JLabel CPUclock = new JLabel("CPU clock = 0");
	//JLabel BUSclock = new JLabel("BUS clock = 0");
	//JLabel MEMclock = new JLabel("MEM clock = 0");
	JLabel maddr = new JLabel("maddr = 0");
	//o JLabel Tmem = new JLabel("Tmem = 0");
	JLabel PC =new JLabel("PC = 0");
	JButton CLK = new JButton("CLK+");
	JButton INS = new JButton("INS+");
	JButton PRG = new JButton("PRG+");
	JLabel asmtxt=new JLabel("Asemblerski kod:");

	JButton reset = new JButton("RESET");
	JButton registers = new JButton("REGISTRI");
	JButton memory = new JButton("MEMORIJA");
	JButton resetnomem = new JButton("RESET BEZ MEM");
	JPanel menu = new JPanel();

	// Labela za oznaku faze
	JLabel phaseName = new JLabel("Faza izvrsavanja:");
	// Labela koja kazuje fazu
	JLabel phase = new JLabel("Citanje instrukcije");
	// Dodatne informacije o fazi
	JLabel phaseExtraInfo = new JLabel("-");
	// Labela za oznaku nacina adresiranja
	JLabel adrName = new JLabel("Adresiranje:");
	// Labela koja kazuje nacina adresiranja
	JLabel adr = new JLabel("-");
	// Oznaka operacije
	JLabel operName = new JLabel("Operacija:");
	// Operacija
	JLabel oper = new JLabel("-");

	// treba dodati opcioju da se resetuje sistem na pocetno stanje

	JTextArea asmtext = new JTextArea();
	
	JButton load = new JButton("Ucitaj u memoriju");
	
	List listOfShemes = new List();
	GuiScheme currentScheme;
	ScrollPane tmp;
	///////////////////// INICIJALIZACIJA MEMORIJE POMOCU ODGOVARAJUCEG ASEMBLERSKOG KODA
	Assembler asm;
	/////////////////////

	CPURegister cpuregs;
	public static JDialog dialogRegs = new JDialog();

	Memory guimem;
	public static JDialog dialogMem = new JDialog();
	public void update(Graphics g){
		paint(g);
	}
	
	//////////////////////////////////////////////////////////////////////////////////////////////	
	public static int clkNumber = 0;
	public static boolean firstTime=true;
	
	
	public Main(){
		super("Djole");
		
		//
		// Inicijalizacija sema
		//
		Addr.init();
		Bus.init();
		Exec1.init();
		Exec2.init();
		Exec3.init();
		Exec4.init();
		Fetch1.init();
		Fetch2.init();
		Fetch3.init();
		Intr1.init();
		Intr2.init();
		Intr3.init();
		UpravljackaJedinica.init();
		UpravOper.init();
		UpravUprav.init();
		MemOper.init();
		MemUprav.init();

		
		//
		// Grafika sema
		//
		Addr.gui();
		Bus.gui();
		Exec1.gui();
		Exec2.gui();
		Exec3.gui();
		Exec4.gui();
		Fetch1.gui();
		Fetch2.gui();
		Fetch3.gui();
		Intr1.gui();
		Intr2.gui();
		Intr3.gui();
		UpravljackaJedinica.gui();
		UpravOper.gui();
		UpravUprav.gui();
		MemOper.gui();
		MemUprav.gui();
		
		//
		// Spoji elemente u semama
		//
		Addr.connect();
		Bus.connect();
		Exec1.connect();
		Exec2.connect();
		Exec3.connect();
		Exec4.connect();
		Fetch1.connect();
		Fetch2.connect();
		Fetch3.connect();
		Intr1.connect();
		Intr2.connect();
		Intr3.connect();
		UpravljackaJedinica.connect();
		UpravOper.connect();
		UpravUprav.connect();
		MemOper.connect();
		MemUprav.connect();
		
		LogicalComponent.initialise();

		cpuregs = new CPURegister();
		guimem = new Memory();
		
		////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		//
		// Prikazi graficki interfejs
		//
		
		
		
		currentScheme = Addr.getGui();
	
		cpuregs.init();
		guimem.init();
		
		//
		//
		// GRAFIKA
		//
		//
		tmp = new ScrollPane(); tmp.add(currentScheme);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		add("Center",tmp);
		
		Dimension d=new Dimension(160, 620);
		east.setMaximumSize(d);
		east.setMinimumSize(d);
		east.setPreferredSize(d);
		east.setSize(d);
		
		
		northeast.setLayout(new GridLayout(2, 1));
		JPanel northeastI=new JPanel();
		northeastI.setLayout(new BoxLayout(northeastI, BoxLayout.Y_AXIS));
		CPUclock.setAlignmentX(CENTER_ALIGNMENT);
		northeastI.add(CPUclock);
		//BUSclock.setAlignmentX(CENTER_ALIGNMENT);
		//northeastI.add(BUSclock);
		//MEMclock.setAlignmentX(CENTER_ALIGNMENT);
		//northeastI.add(MEMclock);
		maddr.setAlignmentX(CENTER_ALIGNMENT);
		northeastI.add(maddr);
		//Tmem.setAlignmentX(CENTER_ALIGNMENT);
		//northeastI.add(Tmem);
		PC.setAlignmentX(CENTER_ALIGNMENT);
		northeastI.add(PC);
		northeast.add(northeastI);
		
		
		//
		// CLK dugme
		//
		CLK.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent arg0) {

				//LogicalComponent.CLK();
				clock();				////////////////////////////////////////////////// za debug

				CPUclock.setText("CPU clock = " + LogicalComponent.globalClock);
				
				PC.setText("PC = "+Fetch1.PC.getVal());
				
				////////////////////////////////////////
				
				String step = Integer.toHexString(UpravljackaJedinica.mPC.getOut(0).getIntVal());
				
				maddr.setText("maddr = " + step);

				// U zavisnosti od koraka T postavi fazu
				setText(step,firstTime);
				firstTime=false;

				currentScheme.repaint();

				if(Exec2.START().getBoolVal() == false){
					CLK.setEnabled(false);
					INS.setEnabled(false);
					PRG.setEnabled(false);
				}

			}
			
		});
		CLK.setAlignmentX(CENTER_ALIGNMENT);
		northeastI.add(CLK);
		
		//
		// INS dugme
		//
		INS.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent arg0) {
				
				
				LogicalComponent.CLK();
				CPUclock.setText("CPU clock = " + LogicalComponent.globalClock);
				maddr.setText("maddr = "+ Integer.toHexString(UpravljackaJedinica.mPC.getOut(0).getIntVal()));
				PC.setText("PC = "+Fetch1.PC.getVal());
				setText(Integer.toHexString(UpravljackaJedinica.mPC.getOut(0).getIntVal()),firstTime);
				firstTime=false;
				currentScheme.repaint();
				if(Exec2.START().getBoolVal() == false){
					CLK.setEnabled(false);
					INS.setEnabled(false);
					PRG.setEnabled(false);
				}
				LogicalComponent.CLK();
				CPUclock.setText("CPU clock = " + LogicalComponent.globalClock);
				maddr.setText("maddr = "+ Integer.toHexString(UpravljackaJedinica.mPC.getOut(0).getIntVal()));
				PC.setText("PC = "+Fetch1.PC.getVal());
				currentScheme.repaint();
				if(Exec2.START().getBoolVal() == false){
					CLK.setEnabled(false);
					INS.setEnabled(false);
					PRG.setEnabled(false);
				}
				// vrti se dok ne dodje do T00
				while ((UpravljackaJedinica.mPC.getOut(0).getIntVal() != 0)&&(Exec2.START().getBoolVal() == true)){
					LogicalComponent.CLK();
					CPUclock.setText("CPU clock = " + LogicalComponent.globalClock);
					maddr.setText("maddr = "+ Integer.toHexString(UpravljackaJedinica.mPC.getOut(0).getIntVal()));
					PC.setText("PC = "+Fetch1.PC.getVal());
					setText(Integer.toHexString(UpravljackaJedinica.mPC.getOut(0).getIntVal()),firstTime);
					currentScheme.repaint();
				}
				if(Exec2.START().getBoolVal() == false){
					CLK.setEnabled(false);
					INS.setEnabled(false);
					PRG.setEnabled(false);
				}
				phase.setText("Izvrsena Instrukcija");
				phaseExtraInfo.setText("Povratak na pocetak");
			}
		});
		INS.setAlignmentX(CENTER_ALIGNMENT);
		northeastI.add(INS);
		
		//
		// PRG dugme
		//
		PRG.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent arg0) {
				while (Exec2.START().getBoolVal() == true) {
					firstTime=false;
					LogicalComponent.CLK();
					CPUclock.setText("CPU clock = " + LogicalComponent.globalClock);
					maddr.setText("maddr = "+ Integer.toHexString(UpravljackaJedinica.mPC.getOut(0).getIntVal()));
					PC.setText("PC = "+Fetch1.PC.getVal());
					setText(Integer.toHexString(UpravljackaJedinica.mPC.getOut(0).getIntVal()),firstTime);
					currentScheme.repaint();
				}
				CLK.setEnabled(false);
				INS.setEnabled(false);
				PRG.setEnabled(false);
			}
		});
		PRG.setAlignmentX(CENTER_ALIGNMENT);
		northeastI.add(PRG);
		
		//
		// Opet neka grafika...
		//
		JPanel northeastII=new JPanel();
		northeastII.setLayout(new BoxLayout(northeastII, BoxLayout.Y_AXIS));
		// Dodati labelu koja kazuje fazu
		phaseName.setAlignmentX(CENTER_ALIGNMENT);
		northeastII.add(phaseName);
		phaseName.setFont(new Font("D", 10, 13));
		phase.setAlignmentX(CENTER_ALIGNMENT);
		northeastII.add(phase);
		phaseExtraInfo.setAlignmentX(CENTER_ALIGNMENT);
		northeastII.add(phaseExtraInfo);
		// Dodati labelu koja kazuje nacin adresiranja
		adrName.setAlignmentX(CENTER_ALIGNMENT);
		northeastII.add(adrName);
		adrName.setFont(new Font("D", 10, 13));
		adr.setAlignmentX(CENTER_ALIGNMENT);
		northeastII.add(adr);
		// Dodati labelu koja kazuje vrstu operacije
		operName.setAlignmentX(CENTER_ALIGNMENT);
		northeastII.add(operName);
		operName.setFont(new Font("D", 10, 13));
		oper.setAlignmentX(CENTER_ALIGNMENT);
		northeastII.add(oper);
		northeast.add(northeastII);
		
		//asmtext.setText("ld #4\nst r0\nld #5\nst r1\nadd r0\nhalt");
		asmtext.setText("ldb #200\nstb r0\nldb #10\nstb r2\nhalt");
		asmtext.setAlignmentX(CENTER_ALIGNMENT);
		asm = new Assembler(getAsm(), null, true);
		
		//
		// Load dugme
		//
		load.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent arg0) {
				asm = new Assembler(getAsm(), null, true);
				JOptionPane.showMessageDialog(load.getParent().getParent().getParent(), "Program ucitan u memoriju","Ucitavanje programa", JOptionPane.PLAIN_MESSAGE);
			}
		});
		load.setAlignmentX(CENTER_ALIGNMENT);
		
		//
		// Memory dugme
		//
		memory.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent arg0) {
				
				dialogMem.setVisible(true);
				currentScheme.repaint();

			}
		});
		memory.setAlignmentX(CENTER_ALIGNMENT);
		
		
		//
		// Registers dugme
		//
		registers.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent arg0) {
				dialogRegs.setVisible(true);
				currentScheme.repaint();
			}
		});
		registers.setAlignmentX(CENTER_ALIGNMENT);
		
		//
		// Reset dugme
		//
		reset.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent arg0) {

				//LogicalComponent.resetSimulation();
				LogicalComponent.initMemory=true;
				LogicalComponent.initialise();
				
				//asm = new Assembler(getAsm(), null, true);
				
				// Podesi labele
				CPUclock.setText("CPU clock = " + LogicalComponent.globalClock);
				maddr.setText("maddr = "+ Integer.toHexString(UpravljackaJedinica.mPC.getOut(0).getIntVal()));
				PC.setText("PC ="+Fetch1.PC.getVal());
				phase.setText("Citanje instrukcije");
				adr.setText("-");
				oper.setText("-");
				phaseExtraInfo.setText("-");

				JOptionPane.showMessageDialog(load.getParent().getParent().getParent(), "Simulacija resetovana","Resetovanje simulacije...", JOptionPane.PLAIN_MESSAGE);
				CLK.setEnabled(true);
				INS.setEnabled(true);
				PRG.setEnabled(true);
				currentScheme.repaint();

			}
		});
		reset.setAlignmentX(CENTER_ALIGNMENT);
		
		//
		// Resetnomem dugme
		//
		resetnomem.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent arg0) {

				//LogicalComponent.resetSimulation();
				LogicalComponent.initMemory=true;
				LogicalComponent.initialise();
				
				// isto kao reset samo ima ovo
				asm = new Assembler(getAsm(), null, true);
				
				// Podesi labele
				CPUclock.setText("CPU clock = " + LogicalComponent.globalClock);
				maddr.setText("maddr = "+ Integer.toHexString(UpravljackaJedinica.mPC.getOut(0).getIntVal()));
				PC.setText("PC ="+Fetch1.PC.getVal());
				phase.setText("Citanje instrukcije");
				adr.setText("-");
				oper.setText("-");
				phaseExtraInfo.setText("-");

				JOptionPane.showMessageDialog(load.getParent().getParent().getParent(), "Simulacija resetovana","Resetovanje simulacije...", JOptionPane.PLAIN_MESSAGE);
				CLK.setEnabled(true);
				INS.setEnabled(true);
				PRG.setEnabled(true);
				currentScheme.repaint();
			}
		});
		resetnomem.setAlignmentX(CENTER_ALIGNMENT);
		
		//
		// Opet neka grafika
		//
		southeast.setLayout(new BoxLayout(southeast, BoxLayout.Y_AXIS));

		// Dodat scroll bar za asemblerski tekst
		//
		asmtxt.setAlignmentX(CENTER_ALIGNMENT);
		southeast.add(asmtxt);

		JScrollPane scrolltxt = new JScrollPane(asmtext);
		scrolltxt.setName("KOD");
		scrolltxt.setAlignmentX(CENTER_ALIGNMENT);
		southeast.add(scrolltxt);
		
		southeast.add(load);

		east.setLayout(new GridLayout(2, 1));
		east.add(northeast);
		east.add(southeast);
		add("East", east);
		
		//
		// Lista sema
		//
		listOfShemes.add("Procesor");
		listOfShemes.add("     Operaciona");
		listOfShemes.add("          Addr");
		listOfShemes.add("          Bus");
		listOfShemes.add("          Exec 1");
		listOfShemes.add("          Exec 2");
		listOfShemes.add("          Exec 3");
		listOfShemes.add("          Exec 4");
		listOfShemes.add("          Fetch 1");
		listOfShemes.add("          Fetch 2");
		listOfShemes.add("          Fetch 3");
		listOfShemes.add("          Intr 1");
		listOfShemes.add("          Intr 2");
		listOfShemes.add("          Intr 3");
		listOfShemes.add("     Upravljacka");
		listOfShemes.add("          Mikro-Memorija");
		listOfShemes.add("          Operacioni");
		listOfShemes.add("          Upravljacki");;
		listOfShemes.add("Memorija");
		listOfShemes.add("      Operaciona jedinica");
		listOfShemes.add("      Upravljacka jedinica");
		//
		listOfShemes.addItemListener(new ItemListener() {
			public void itemStateChanged(ItemEvent arg0) {

				//remove(currentScheme);
				remove(tmp);
				if (listOfShemes.getSelectedItem().equals("          Addr") || listOfShemes.getSelectedItem().equals("Procesor") || listOfShemes.getSelectedItem().equals("     Operaciona")) {
					currentScheme = Addr.getGui();
					
				} else if (listOfShemes.getSelectedItem().equals(
						"          Bus")) {
					currentScheme = Bus.getGui();

				} else if (listOfShemes.getSelectedItem().equals(
						"          Exec 1")) {
					currentScheme = Exec1.getGui();
					
				} else if (listOfShemes.getSelectedItem().equals(
						"          Exec 2")) {
					currentScheme = Exec2.getGui();
					
				} else if (listOfShemes.getSelectedItem().equals(
						"          Exec 3")) {
					currentScheme = Exec3.getGui();
					
				} else if (listOfShemes.getSelectedItem().equals(
						"          Exec 4")) {
					currentScheme = Exec4.getGui();
					
				} else if (listOfShemes.getSelectedItem().equals(
						"          Fetch 1")) {
					currentScheme = Fetch1.getGui();
					
				} else if (listOfShemes.getSelectedItem().equals(
						"          Fetch 2")) {
					currentScheme = Fetch2.getGui();
					
				} else if (listOfShemes.getSelectedItem().equals(
						"          Fetch 3")) {
					currentScheme = Fetch3.getGui();
					
				} else if (listOfShemes.getSelectedItem().equals(
						"          Intr 1")) {
					currentScheme = Intr1.getGui();
					
				} else if (listOfShemes.getSelectedItem().equals(
						"          Intr 2")) {
					currentScheme = Intr2.getGui(); 
					
				} else if (listOfShemes.getSelectedItem().equals(
						"          Intr 3")) {
					currentScheme = Intr3.getGui();
					
				} else if (listOfShemes.getSelectedItem().equals(
						"      Operaciona jedinica") || listOfShemes.getSelectedItem().equals(
						"Memorija")) {
					currentScheme = MemOper.getGui();
					
				} else if (listOfShemes.getSelectedItem().equals(
						"      Upravljacka jedinica")) {
					currentScheme = MemUprav.getGui();
					
				} else if (listOfShemes.getSelectedItem().equals(
						"          Mikro-Memorija") || listOfShemes.getSelectedItem().equals(
						"     Upravljacka")) {
						currentScheme = UpravljackaJedinica.getGui();
					
				} else if (listOfShemes.getSelectedItem().equals(
						"          Operacioni")) {
					currentScheme = UpravOper.getGui();
					
				} else if (listOfShemes.getSelectedItem().equals(
						"          Upravljacki")) {
					currentScheme = UpravUprav.getGui();
				}
				//add(currentScheme);
				tmp.removeAll();
				tmp.add(currentScheme);
				add(tmp);
				repaint();
				validate();
			}
		});
		
		
		//
		//
		// I opet neka grafika
		//
		west.setLayout(new BorderLayout());
		west.add(listOfShemes, BorderLayout.CENTER);
		menu.setLayout(new GridLayout(4, 1));
		menu.add(memory);
		menu.add(registers);
		menu.add(reset);
		menu.add(resetnomem);
		west.add(menu, BorderLayout.SOUTH);
		add("West", west);
		;
		validate();
		setBounds(0, 0, currentScheme.getWidth() + listOfShemes.getWidth()
				+ asmtext.getWidth() + 320, currentScheme.getHeight() + 40);
		setVisible(true);

		// Ucitaj na pocetku default program
		//String asmcode = asmtext.getText();
		//asm.asembly(asmcode);

		dialogRegs.setResizable(false);
		dialogRegs.setTitle("CPU registri");
		dialogRegs.setModal(true);
		dialogRegs.addWindowListener(new WindowAdapter() {

			public void windowClosing(WindowEvent arg0) {
				dialogRegs.setVisible(false);
				currentScheme.repaint();
			}

		});
		cpuregs.setSadrzalacRegistara(dialogRegs);
		dialogRegs.add(cpuregs);
		dialogRegs.setSize(600, 600);
		dialogRegs.setLocation(100, 100);
		dialogRegs.setVisible(false);

		dialogMem.setResizable(false);
		dialogMem.setTitle("Pregled Memorije");
		dialogMem.setModal(true);
		dialogMem.addWindowListener(new WindowAdapter() {

			public void windowClosing(WindowEvent arg0) {
				dialogMem.setVisible(false);
				currentScheme.repaint();
			}

		});
		guimem.setSadrzalacMemorije(dialogMem);
		dialogMem.add(guimem);
		dialogMem.setSize(500, 300);
		dialogMem.setLocation(100, 100);
		dialogMem.setVisible(false);
		
		
		setSize(1050,UpravUprav.getGui().getHeight()-130);
		//setResizable(false);
		
		//setSize(1050,UpravUprav.getGui().getHeight()+30);
		//setResizable(false);
		
		Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
		this.setLocation(dim.width/2-this.getSize().width/2, dim.height/2-this.getSize().height/2);
		
		
	}
	
	public static void main(String[] args) {
		
		
		new Main();
		
	}
	
	public static void help() {
		BufferedReader reader=null;
		try {
			reader = new BufferedReader(new FileReader("conf/jmvm/MMhelp"));
			String line = null;
			while ((line = reader.readLine()) != null) {
			 	
				String tmp = line.replaceAll("[^\\w]", "");
				System.out.println(tmp);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
        	if(reader!=null)
				try {
					reader.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
        }
		
	}
	
	public static void clock() {
		LogicalComponent.CLK();
		System.out.println("---------------------------------------------------------------" + " Broj takta: "+(clkNumber++)+" mPC: "+Integer.toHexString(UpravljackaJedinica.mPC.getOut(0).getIntVal()));
		Bus.ispisiRegistre();
		Fetch1.ispisiRegistre();
		Exec1.ispisiRegistre();
		Addr.ispisiRegistre();
		Intr3.ispisiRegistre();
		Exec2.ispisiFlegove();
		Intr1.ispisiFlegove();
		UpravljackaJedinica.ispisiMagistrale();
		UpravljackaJedinica.ispisiUpravSignale();
		UpravljackaJedinica.ispisiOperSignale();
		UpravljackaJedinica.ispisiIzlazMM();
		MemOper.ispisiSignale();
		MemUprav.ispisiSignale();
		//System.out.println(Addr.GPRegs.regs[2]);
		/*System.out.println(" 4096: "+MemOper.RAM.read(4096));
		System.out.println(" 4097: "+MemOper.RAM.read(4097));
		System.out.println(" 4098: "+MemOper.RAM.read(4098));
		System.out.println(" 4099: "+MemOper.RAM.read(4099));
		System.out.println(" 4100: "+MemOper.RAM.read(4100));
		System.out.println(" 4101: "+MemOper.RAM.read(4101));
		System.out.println(" 4102: "+MemOper.RAM.read(4102));
		System.out.println(" 4103: "+MemOper.RAM.read(4103));
		System.out.println(" 0: "+MemOper.RAM.read(0));
		System.out.println(" 1: "+MemOper.RAM.read(1));
		System.out.println(" 2: "+MemOper.RAM.read(2));
		System.out.println(" 3: "+MemOper.RAM.read(3));
		System.out.println(" 4: "+MemOper.RAM.read(4));
		System.out.println(" 5: "+MemOper.RAM.read(5));
		System.out.println(" 6: "+MemOper.RAM.read(6));
		System.out.println(" 7: "+MemOper.RAM.read(7));*/
		System.err.println(" IBUS_L= "+Bus.IBUS_L().getIntVal());
		
	}
	
	public String getAsm() {
		return asmtext.getText();
	}
	
public void setText(String step, boolean firstTime) {
		
		// U zavisnosti od koraka T postavi fazu
		if ("0".equals(step) && !firstTime) {
			phase.setText("Izvrsena Instrukcija");
			phaseExtraInfo.setText("Povratak na pocetak");
		} 
		else if ("1".equals(step)){
			phase.setText("Citanje instrukcije");
			adr.setText("-");
			oper.setText("-");
			phaseExtraInfo.setText("-");
		}
		else if ("2".equals(step))
			phaseExtraInfo.setText("Dohvatanje prvog bajta");
		else if ("9".equals(step))
			phaseExtraInfo.setText("Dohvatanje drugog bajta");
		else if ("11".equals(step))
			phaseExtraInfo.setText("Dohvatanje treceg bajta");
		else if ("16".equals(step))
			phaseExtraInfo.setText("Dohvatanje cetvrtog bajta");
		else if ("20".equals(step)) {
			phase.setText("Formiranje adr i citanje oper");
			phaseExtraInfo.setText("-");
		} else if ("21".equals(step))
			adr.setText("Registarsko direktno");
		else if ("25".equals(step))
			adr.setText("Registarsko indirektno");
		else if ("27".equals(step))
			adr.setText("Memorijsko direktno");
		else if ("29".equals(step))
			adr.setText("Memorijsko indirektno");
		else if ("32".equals(step))
			adr.setText("Registarsko ind. sa pomerajem");
		else if ("36".equals(step))
			adr.setText("Bazno indeksno sa pomerajem");
		else if ("3c".equals(step))
			adr.setText("PC relativno");
		else if ("48".equals(step))
			adr.setText("Neposredno");
		else if ("50".equals(step)) {
			phase.setText("Izvrsavanje operacije");
			phaseExtraInfo.setText("-");
		} else if ("51".equals(step))
			oper.setText("NOP");
		else if ("52".equals(step))
			oper.setText("HALT");
		else if ("53".equals(step))
			oper.setText("INTD");
		else if ("54".equals(step))
			oper.setText("INTE");
		else if ("55".equals(step))
			oper.setText("TRPD");
		else if ("56".equals(step))
			oper.setText("TRPE");
		else if ("57".equals(step))
			oper.setText("LDB");
		else if ("59".equals(step))
			oper.setText("LDW");
		else if ("5a".equals(step))
			oper.setText("STB");
		else if ("60".equals(step))
			oper.setText("STW");
		else if ("69".equals(step))
			oper.setText("POPB");
		else if ("6f".equals(step))
			oper.setText("POPW");
		else if ("79".equals(step))
			oper.setText("PUSHB");
		else if ("7f".equals(step))
			oper.setText("PUSHW");
		else if ("8a".equals(step))
			oper.setText("LDIVTP");
		else if ("8b".equals(step))
			oper.setText("STIVTP");
		else if ("8c".equals(step))
			oper.setText("LDIMR");
		else if ("8d".equals(step))
			oper.setText("STIMR");
		else if ("8E".equals(step))
			oper.setText("LDSP");
		else if ("8F".equals(step))
			oper.setText("STSP");
		else if ("90".equals(step))
			oper.setText("ADD");
		else if ("92".equals(step))
			oper.setText("SUB");
		else if ("94".equals(step))
			oper.setText("INC");
		else if ("96".equals(step))
			oper.setText("DEC");
		else if ("98".equals(step))
			oper.setText("AND");
		else if ("9a".equals(step))
			oper.setText("OR");
		else if ("9c".equals(step))
			oper.setText("XOR");
		else if ("9e".equals(step))
			oper.setText("NOT");
		else if ("a0".equals(step)){
			if(Fetch2.ASR().getBoolVal())oper.setText("ASR");
			else if (Fetch2.LSR().getBoolVal())oper.setText("LSR");
			else if (Fetch2.ROR().getBoolVal())oper.setText("ROR");
			else if (Fetch2.RORC().getBoolVal())oper.setText("RORC");
		}
		else if ("a2".equals(step)){
			if(Fetch2.ASL().getBoolVal())oper.setText("ASL");
			else if (Fetch2.LSL().getBoolVal())oper.setText("LSL");
			else if (Fetch2.ROL().getBoolVal())oper.setText("ROL");
			else if (Fetch2.ROLC().getBoolVal())oper.setText("ROLC");
		}
		else if ("a4".equals(step)){
			if (Fetch2.BEQL().getBoolVal())oper.setText("BEQL");
			else if (Fetch2.BNEQL().getBoolVal())oper.setText("BNEQL");
			else if (Fetch2.BNEG().getBoolVal())oper.setText("BNEG");
			else if (Fetch2.BNNEG().getBoolVal())oper.setText("BNNEG");
			else if (Fetch2.BOVF().getBoolVal())oper.setText("BOVF");
			else if (Fetch2.BNOVF().getBoolVal())oper.setText("BNOVF");
			else if (Fetch2.BCAR().getBoolVal())oper.setText("BCAR");
			else if (Fetch2.BNCAR().getBoolVal())oper.setText("BNCAR");
			else if (Fetch2.BGRT().getBoolVal())oper.setText("BGRT");
			else if (Fetch2.BGRTE().getBoolVal())oper.setText("BGRTE");
			else if (Fetch2.BLSS().getBoolVal())oper.setText("BLSS");
			else if (Fetch2.BLSSE().getBoolVal())oper.setText("BLSSE");
			else if (Fetch2.BGRTU().getBoolVal())oper.setText("BGRTU");
			else if (Fetch2.BGRTEU().getBoolVal())oper.setText("BGRTEU");
			else if (Fetch2.BLSSU().getBoolVal())oper.setText("BLSSU");
			else if (Fetch2.BLSSEU().getBoolVal())oper.setText("BLSSEU");
		}
		else if ("a8".equals(step))
			oper.setText("JMP");
		else if ("a9".equals(step))
			oper.setText("INT");
		else if ("aa".equals(step))
			oper.setText("JSR");
		else if ("b5".equals(step))
			oper.setText("RTI");
		else if (("bd".equals(step))&&(Fetch2.RTS().getBoolVal()))
			oper.setText("RTS");
		else if ("d0".equals(step)) {
			phase.setText("Opsluzivanje prekida");
			phaseExtraInfo.setText("-");
		} else if ("d1".equals(step))
			phaseExtraInfo.setText("Cuvanje konteksta");
		else if ("e5".equals(step))
			phaseExtraInfo.setText("Utvrdjivanje broja ulaza");
		else if ("f0".equals(step))
			phaseExtraInfo.setText("Utvrdjivanje adrese prekidne rutine");
		
	}

}


